Previous Thread
Next Thread
Print Thread
Rate Thread
#224293 09/08/2002 12:07 PM
Joined: Nov 2001
Posts: 10,369
I type Like navaho
I type Like navaho
Joined: Nov 2001
Posts: 10,369
Hey guys.... a little PHP help please. I'm running this to calculate and display the file size of the attachment in showflat and showthreaded view. BUT.... sometimes... for some reason it leaves the filesize off and just prints the word " Bytes" with no number before it.

Basically it gets the filesize (in bytes)... then displays it as MB, KB or if its not big enough for either of those... it's supposed to display the total in Bytes. But I can't figure out why sometimes it doesn't work right. Any ideas?

code:

$File = rawurlencode($File);
$thefile = "{$config['files']}/$File";
// Define some file sizes
$kb = 1024; // Kilobyte
$mb = 1048576; // Megabyte
// Get the file size in bytes.
$attachmentsize = filesize($thefile);
//If it's less than a kb we just return the size, otherwise we keep going until
//the size is in the appropriate measurement range.
if($attachmentsize > $mb) {
$filesize = round($attachmentsize/$mb,2)." MB";
}
elseif($attachmentsize > $kb) {
$filesize = round($attachmentsize/$kb,2)." KB";
}
else {
$filesize = $attachmentsize." Bytes";
}



Then it plugs the $filesize variable into the post just after the download count.

Thanks for your help.... I'm sure this is a breeze for you "pros".

Last edited by Dave_L; 09/08/2002 1:00 PM.
Sponsored Links
Daine #224294 09/08/2002 12:24 PM
Joined: Nov 2001
Posts: 10,369
I type Like navaho
I type Like navaho
Joined: Nov 2001
Posts: 10,369
OK -
I actually know what is wrong.

it's not really with my code..... if the Filename has a "space" in it..... it doesn't calculate the filesize.

Does anyone have any idea how you can get the filesize of a file with a space in it. Perhaps it's special characters in general.

I went to one I was having trouble with and took the spaces out of the file field in the database...and renamed the file and it worked fine.

Any help is greatly appreciated.

:)

Daine #224295 09/08/2002 12:58 PM
Joined: Apr 2002
Posts: 1,768
Addict
Addict
Offline
Joined: Apr 2002
Posts: 1,768
I think that $File = rawurlencode($File); is the problem. Functions such as filesize() expect the actual file name, not the URL-encoded form.

P.S. I edited your post to remove the leading spaces from the code, so that horizontal scrolling is not required.

joeuser #224296 09/08/2002 1:18 PM
Joined: Nov 2001
Posts: 10,369
I type Like navaho
I type Like navaho
Joined: Nov 2001
Posts: 10,369
Cool!!!

Thank you.

the $File = rawurlencode($File);
was part of threads... but I moved it after my filesize code and that seems to have done the trick.

Thank you!


Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Shock Hosting
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
isaac
isaac
California
Posts: 1,153
Joined: July 2001
Forum Statistics
Forums63
Topics37,583
Posts293,955
Members13,824
Most Online151,614
Nov 14th, 2025
Today's Statistics
Currently Online 464
Topics Created 0
Posts Made 0
Users Online 0
Birthdays 13
Top Posters
AllenAyres 21,080
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,834
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2026 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.1.0
(Snapshot build 20260108)